<template>
  <div>
    <FormPanel :list="formList" labelWidth="100" :isSubmitBtn="false"></FormPanel>
    <FilterTable
      ref="table"
      :isSelectColumn="false"
      columnsRef="yfkmxcxdTable"
      :columns="columns"
      :fetchapi="fetchApi"
      height="auto"
      :params="fetchParams"
      :datakey="'rows'"
      :onColumnsChange="columns => (this.columns = columns)"
    ></FilterTable>
  </div>
</template>
<script>
import { queryPrePay, getAllUser } from '@/api/finance/advancesReceived/registerQuery';
import { dictionary } from '@/utils/dictMixin';
export default {
  mixins: [dictionary],
  props: ['formData','queryType'],
  data() {
    return {
      formList: this.createTopFilters(),
      fetchParams: {
        customerCode: this.formData.CUSTOMER_CODE,
        isQueryAllInfo: 10041001,
        queryType:this.queryType
      },
      visible: false,
      fetchApi: queryPrePay,
      columns: this.createTableColumns()
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  created() {
    this.getDictList();
    console.log(this.formData.RECEIVE_TYPE, '父页面数据');
    this.formList.forEach(x => {
      x.initialValue = this.formData[x.fieldName];
    });
  },
  methods: {
    createTopFilters() {
      return [
        {
          type: 'INPUT',
          label: '客户编号',
          fieldName: 'CUSTOMER_CODE',
          placeholder: '请输入...',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '客户名称',
          fieldName: 'CUSTOMER_NAME',
          placeholder: '请输入...',
          disabled: true
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '预收款单号',
          dataIndex: 'PRE_RECEIVE_NO',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '发生时间',
          dataIndex: 'HANDLE_TIME',
          sorter: true,
          filter: true,
          filterType: 'input',
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '收款类别',
          dataIndex: 'RECEIVE_TYPE',
          sorter: true,
          filter: true,
          filterType: 'input',
          filterItems: this.createDictList('8030'),
          render: props => {
            return <span>{this.createDictText(props.row.RECEIVE_TYPE, '8030')}</span>;
          }
        },
        {
          title: '经手人',
          dataIndex: 'HANDLER',
          sorter: true,
          editable: false,
          editType: 'select',
          editItems: [],
          filterType: 'input'
        },
        {
          title: '客户编码',
          dataIndex: 'CUSTOMER_CODE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '客户名称',
          dataIndex: 'CUSTOMER_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车牌号',
          dataIndex: 'LICENSE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        // {
        //   title: 'VIN',
        //   dataIndex: 'VIN',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input',
        //   width: 200
        // },
        {
          title: '收款金额',
          dataIndex: 'RECEIVE_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2
        },
        {
          title: '本次支出',
          dataIndex: 'PAYOUT_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2
        },
        {
          title: '本次结余',
          dataIndex: 'AFTER_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2
        },
        {
          title: '付款方式',
          dataIndex: 'PAY_TYPE_CODE',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('8044'),
          render: props => {
            return <span>{this.createDictText(props.row.PAY_TYPE_CODE, '8044')}</span>;
          }
        },
        {
          title: '支票号码',
          dataIndex: 'CHECK_NO',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '票据号码',
          dataIndex: 'BILL_NO',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '发票类型',
          dataIndex: 'INVOICE_TYPE_NAME',
          sorter: true,
          filter: true,
          filterType: 'input',
          width: 200
        },
        {
          title: '备注',
          dataIndex: 'REMARK',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        }
      ];
    },
    async getDictList() {
      // employeeName翻译
      this.columns.find(x => x.dataIndex === 'HANDLER').editItems = (await getAllUser()).data.map(x => ({ text: x.employeeName, value: x.userId + '' }));
    },
    closeHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    }
  }
};
</script>

<style lang="less" scoped></style>
